package com.sc.nft.entity.vo;

import cn.hutool.core.bean.BeanUtil;
import com.google.common.collect.Lists;
import com.sc.nft.entity.PledgeTaskReward;
import com.sc.nft.enums.PledgeTaskRewardTypeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Data
public class PledgeTaskCollectionVO {

    @ApiModelProperty("秘境id")
    private Long pledgeTaskId;

    @ApiModelProperty("质押任务id")
    private Long pledgeTaskCollectionId;

    @ApiModelProperty("秘境名称")
    private String pledgeTaskName;

    @ApiModelProperty("藏品id")
    private Long collectionId;

    @ApiModelProperty("藏品图片")
    private String collectionImage;

    @ApiModelProperty("藏品名称")
    private String firstTitle;

    @ApiModelProperty("质押藏品份数")
    private Integer pledgeCount;

    @ApiModelProperty("连续持仓时间")
    private Integer pledgeTime;

    @ApiModelProperty("质押状态 1:可以质押 2:挖宝中 3:去获取")
    private Integer isPledge;

    @ApiModelProperty(value = "二级市场配置id")
    private Long secondCollectionConfigId = 0L;

    @ApiModelProperty("质押任务奖励列表")
    private List<PledgeTaskRewardVO> pledgeTaskRewardList;

    public void setPledgeTaskRewardList(List<PledgeTaskReward>  list) {
        List<PledgeTaskRewardVO> pledgeTaskRewardList = Lists.newArrayList();
        if(list.size() == 0){
            this.pledgeTaskRewardList = pledgeTaskRewardList;
        }

        for (PledgeTaskReward pledgeTaskReward : list) {
            PledgeTaskRewardVO pledgeTaskRewardVO = BeanUtil.copyProperties(pledgeTaskReward, PledgeTaskRewardVO.class);
            if(pledgeTaskReward.getLinkType() == PledgeTaskRewardTypeEnum.POINTS){
                pledgeTaskRewardVO.setLinkCount(pledgeTaskReward.getLinkCount().setScale(2,BigDecimal.ROUND_DOWN).toPlainString());
            }

            if(pledgeTaskReward.getLinkType() == PledgeTaskRewardTypeEnum.EQUITY_PROP || pledgeTaskReward.getLinkType() == PledgeTaskRewardTypeEnum.NFT){
                pledgeTaskRewardVO.setLinkCount(pledgeTaskReward.getLinkCount().stripTrailingZeros().toPlainString());
            }
            pledgeTaskRewardList.add(pledgeTaskRewardVO);
        }
        this.pledgeTaskRewardList = pledgeTaskRewardList;

    }
}
